package com.mall.malladminbackend.controller;

import com.mall.malladminbackend.dto.SpecKeyDto;
import com.mall.malladminbackend.model.R;
import com.mall.malladminbackend.service.SpecKeyService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 作者：tk
 * 时间：2022/8/15 13:47
 * 描述：永无Bug!!!
 */
@RestController
@RequestMapping("/spec")
@AllArgsConstructor
public class SpecKeyController {
    private SpecKeyService specKeyService;
    //分页
    @GetMapping
    public R getPaging(@RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "5") Integer pageSize){
        return specKeyService.getSpecAll(pageNum,pageSize);
    }
    //添加
    @PostMapping("/insert")
    public R insertSpec(@RequestBody SpecKeyDto specKeyDto) throws Exception {
        return specKeyService.addSpec(specKeyDto);
    }
    //删除
    @DeleteMapping("/{id}")
    public R delSpecsById(@PathVariable Integer id){
        return specKeyService.deleteSpec(id);
    }
    //根据id查询
    @GetMapping("/select/{id}")
    public R getSpecsById(@PathVariable Integer id){
        return specKeyService.selectSpecsById(id);
    }
    //编辑
    @PutMapping("update")
    public R updateSpecById(@RequestBody SpecKeyDto specKeyDto) throws Exception {
        return specKeyService.updateSpecs(specKeyDto);
    }

      @GetMapping("/all")
     public R getAllspec(){
       return specKeyService.getAllSpecKey();
     }
}
